import Vuex from 'vuex'
// vue组件
import Vue from 'vue'
// 状态管理
Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		isUser: window.localStorage.getItem('token') ? true : false,
		isLoginOpen: false,
		integral: true,
	},
	actions: {

	},
	mutations: {
		// 更新用户是否注册
		upIsUser (state, payload) {
			state.isUser = payload.isUser
			// 是否需要领取积分----只需要登录的页面则为false
			state.integral = payload.integral || state.integral
		},

		// 更新是否需要领取积分
		upIntegral (state, payload) {
			state.integral = payload.integral
		},

		// 更新登陆是否弹窗
		upLoginOpen (state, payload) {
			state.isLoginOpen = payload.isOpen
		},
	},
	getters: {
		// 获取用户是否注册
		getIsUser (state, getters) {
			return state.isUser;
		},

		// 获取是否需要领取积分
		getIntegral (state, getters) {
			return state.integral;
		},

		// 获取是否打开登录弹窗
		getLoginOpen (state, getters) {
			return state.isLoginOpen;
		}
	},
	modules: {

	}
})

export default store